package fasttext.utils;

import java.io.IOException;
import java.io.StringReader;

import org.wltea.analyzer.cfg.Configuration;
import org.wltea.analyzer.cfg.DefaultConfig;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

public class FenCi {
    private static Configuration m_wordCut_cfg;

    public static void main(String[] args) throws IOException {
        String s = "这节课我们讲授c语言里的结构体和宏";
        wordCut(s);
    }

    public static void wordCut(String query) throws IOException {
        m_wordCut_cfg = DefaultConfig.getInstance();
        System.out.println(m_wordCut_cfg.getMainDictionary()); // 系统默认词库
        System.out.println(m_wordCut_cfg.getQuantifierDicionary());

        StringReader input = new StringReader(query.trim());
        // true 用智能分词/false细粒度
        IKSegmenter ikSeg = new IKSegmenter(input, true);

        Lexeme lexeme = ikSeg.next();
        for (; lexeme != null; lexeme = ikSeg.next()) {
            // 禁用默认词典，只用自定义词典
            // 1.默认词典设为停用词典
            // 2.getLexemeType为64的直接跳过
            int nType = lexeme.getLexemeType();
            if (nType == 64) {
                continue;
            }
            System.out.print(lexeme.getLexemeText() + " ");
        }

    }
}
